package game;
import java.util.Scanner;
public class Game {
    int Count;
    User user;
    Computer computer;
    public void initGame(){
        user=new User();
        computer=new Computer();
    }
    public void startGame() {
        while (true) {
            Scanner sc=new Scanner(System.in);
            int usernum=user.show();
            int computernum= computer.show();
            Count++;
            judgeOne(usernum,computernum);
            System.out.println("是否继续，输入y继续下一局");
            String flog = sc.next();
            if (!flog.equals("y")) {
                System.out.println("游戏结束");
                break;
            }
        }
        showResult();
    }
    public void judgeOne(int usernum,int computernum){
        if (usernum==computernum) {
            System.out.println(user.showName(usernum)+"\t"+computer.showName(computernum));
            System.out.println("平局");
        } else if ((usernum==1&&computernum==2)||(usernum==2&&computernum==3)||(usernum==3&&computernum==1)) {
            System.out.println(user.showName(usernum)+"\t"+computer.showName(computernum));
            System.out.println("用户赢了");
            user.WinCount++;
        } else {
            System.out.println(user.showName(usernum)+"\t"+computer.showName(computernum));
            System.out.println("电脑赢了");
            computer.WinCount++;
        }
    }
    public void showResult(){
        System.out.println("用户总次数："+Count);
        System.out.println("用户赢了"+user.WinCount+"次");
        System.out.println("电脑赢了"+computer.WinCount+"次");
        if (user.WinCount>computer.WinCount) {
            System.out.println("用户获胜");
        }else if(user.WinCount==computer.WinCount){
            System.out.println("平局");
        }
        else {
            System.out.println("电脑获胜");
        }
        System.out.println("游戏结束");
    }
}
